package com.itheima.health.dao;

import com.itheima.health.pojo.entity.HostSetmeal;
import com.itheima.health.pojo.entity.Member;
import com.itheima.health.pojo.entity.Order;
import com.itheima.health.pojo.entity.Order;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;

@Mapper
public interface OrderDao {
    /**
     * 根据日期间隔 获取日期段内的预约数量
     *
     * @param date
     * @param dateBefore
     * @return
     */
    Integer getByOrderDate(LocalDate date, LocalDate dateBefore);

    /**
     * 获取当日的预约数量
     *
     * @param date
     * @return
     */
    Integer getByNow(LocalDate date);

    /**
     * 获取当日的到诊数量
     *
     * @param status
     * @param date
     * @return
     */
    Integer getByFileNumberAndNow(String status, LocalDate date);

    /**
     * 根据日期间隔 获取日期段内的到诊数量
     *
     * @param status
     * @param date
     * @param dateBefore
     * @return
     */
    Integer getByFileNumber(String status, LocalDate date, LocalDate dateBefore);

    /**
     * 统计预约总人数
     *
     * @return
     */
    Integer count();

    ArrayList<HostSetmeal> getBySetmeal();

    //新增预约
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into t_order (member_id, orderDate, orderType, orderStatus, setmeal_id) " +
            "values (#{memberId},#{orderDate},#{orderType},#{orderStatus},#{setmealId})")
    void insert(Order order);

    //根据用户id，套餐id和日期查询预约
    @Select("select * from t_order where member_id = #{memberId} and orderDate = #{orderDate} and setmeal_id = #{setmealId}")
    Order selectByMemberIdAndOrderDateAndSetmealId(Integer memberId, Date orderDate, Integer setmealId);

    Order selectById(Integer id);

    Member selectMemberById(Integer memberId);
}
